<?php

namespace app\common\model\user;

use app\api\model\User;
use app\common\model\CargoGoods;
use cores\BaseModel;

class Order extends BaseModel
{
    protected $name = 'user_order';
    protected $pk = 'order_id';


    protected $append = [
        'pay_datetime'
    ];

    const ORDER_SOURCE_CAR = 1;
    const ORDER_SOURCE_LUCKY = 2;

    public function getPayDatetimeAttr($value, $data)
    {
        return isset($data['pay_time']) && $data['pay_time'] > 0 ? date('Y-m-d H:i:s') : '';
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'user_id');
    }

    public function goods()
    {
        return $this->belongsTo(CargoGoods::class, 'goods_id', 'cargo_id');
    }
}